package com.tgy.JUC.FinalLock;

import java.util.concurrent.TimeUnit;

/***
 * @ClassName: SpinTest
 * @Description:
 * @Auther: 送你一块二向箔
 * @Date: 16:59 2022/3/16
 * @version : V1.0
 */
public class SpinTest {
    public static void main(String[] args) {
        SpinLockDemo lock = new SpinLockDemo();
        new Thread(() -> {
            lock.myLock();
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock.myUnLock();
            }
        }, "T1 ").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            lock.myLock();
            lock.myUnLock();
        }, "T2 ").start();
    }
}

